CallGraph
gprofparser.cpp
Go to the documentation of this file.
00001 #include "gprofparser.h"
00002 #include <wx/intl.h> 
00003 #include <wx/regex.h>
00004 #include <wx/strconv.h> 
00005 
00006 GprofParser::GprofParser()
00007 {
00008         lineheader = false;
00009         primaryline = false;
00010         nameLen = 0;
00011         nameandid = NULL; 
00012         isdot = false;
00013         iscycle = false;
00014         islom = false;
00015         isplus = false;
00016         
00017 };
00018 
00019 GprofParser::~GprofParser()
00020 {
00021         lines.DeleteContents(true);
00022         lines.Clear();
00023 };
00024 
00025 void GprofParser::GprofParserStream(wxInputStream *m_pInputStream)
00026 {
00027         readlinetext = wxT("");
00028         readlinetexttemp = wxT("");
00029         wxCSConv conv( wxT("ISO-8859-1") );
00030         wxTextInputStream text(*m_pInputStream);//, wxT(" \t"), conv);
00031         //
00032         while(!m_pInputStream->Eof())
00033         {
00034                 readlinetext = text.ReadLine();
00035                 nameLen = readlinetext.Len();
00036                 
00037                 //if( nameandid ) delete [] nameandid; 
00038                 //nameandid = new wxChar[nameLen + 1];
00039                 
00040                 if(readlinetext != wxT(""))
00041                 {       
00042                         if(readlinetext == wxT("index % time    self  children    called     name"))
00043                         {
00044                                 lineheader = true;
00045                         }
00046                         else if (readlinetext[0] == wxT('-'))
00047                         {
00048                                 primaryline = false;
00049                                 continue;
00050                         }
00051                         else if (readlinetext == wxT("                                                 <spontaneous>"))
00052                         {
00053                                 continue;
00054                         }
00055                         else if (lineheader)
00056                         {       
00057                                 delete [] nameandid; 
00058                                 nameandid = new char[nameLen + 1]; // dynam array for pointer nameandid
00059                                 
00060                                 LineParser *line = new LineParser();
00061                                 
00062                                 //inicializace struktury
00063                                 line->called0 = -1;
00064                                 line->called1 = -1;
00065                                 line->child = false;
00066                                 line->childern = -1;
00067                                 line->cycle = false;
00068                                 line->cycleid = -1;
00069                                 line->index = -1;
00070                                 line->name = wxT("<undefined>");
00071                                 line->nameid = -1;
00072                                 line->parents = false;
00073                                 line->pline = false;
00074                                 line->recursive = false;
00075                                 line->self = -1;
00076                                 line->time = -1;
00077                                                         
00078                                 
00079                                 wxRegEx removeSpace;
00080                                 if( removeSpace.Compile( wxT("[ ]{2,}") ) )
00081                                 {
00082                                         if( removeSpace.Matches( readlinetext ) )
00083                                         {
00084                                                 removeSpace.Replace( &readlinetext, wxT(" ") );
00085                                         }
00086                                 }
00087                                 //
00088                                 
00089                                 if (readlinetext.Contains(wxT("."))) isdot = true;
00090                                 else isdot = false;
00091                                 
00092                                 if (readlinetext.Contains(wxT("cycle"))) iscycle = true;
00093                                 else iscycle = false;
00094                                 
00095                                 if (readlinetext.Contains(wxT("/"))) islom = true;
00096                                 else islom = false;
00097                                 
00098                                 if (readlinetext.Contains(wxT("+"))) isplus = true;
00099                                 else isplus = false;
00100                                 
00101                                 wxString dot = wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER);
00102                                 readlinetext.Replace( wxT("."), dot );
00103                                 
00104                                 //nahrazeni plus za mezeru
00105                                 if(isplus)
00106                                 {
00107                                         readlinetext.Replace( wxT("+"), wxT(" ") );
00108                                 }
00109                                 
00110                                 if ((readlinetext[0] == '[') && (readlinetext[(readlinetext.length()) - 1] == ']'))
00111                                 {
00112                                         primaryline = true;
00113                                         //
00114                                         if(iscycle && isplus) // [3]     91.71    1.77        0.00    1+5    <cycle 1 as a whole> [3]
00115                                         {                                                                                                                                                                                               //warning
00116                                                 sscanf((const char*)readlinetext.mb_str(conv),"[%d] %f %f %f %d %d <cycle %d as a whole> [%d]",&line->index,&line->time,&line->self,&line->childern,&line->called0,&line->called1,&line->cycleid,&line->nameid);
00117                                                 line->name = wxT("whole");
00118                                                 line->parents = false;
00119                                                 line->pline = true;
00120                                                 line->child = false;
00121                                                 line->cycle = true;
00122                                                 line->recursive = true;                                         
00123                                         }
00124                                         else if(iscycle) //  [5]     38.86    0.75        0    1      a <cycle 1> [5]
00125                                         {
00126                                                 sscanf((const char*)readlinetext.mb_str(conv),"[%d] %f %f %f %d %[^\n]s",&line->index,&line->time,&line->self,&line->childern,&line->called0,nameandid);
00127                                                 
00128                                                 wxString readlinesubtext(nameandid, conv); // musi byt kodovani ?
00129                                                 line->name = readlinesubtext.BeforeFirst(wxT('<'));
00130                                                 wxSscanf(readlinesubtext.AfterFirst(wxT('<')).BeforeFirst(wxT('>')),wxT("cycle %d"), &line->cycleid);
00131                                                  //line->cycleid = readlinesubtext.AfterFirst('<').BeforeFirst('>');
00132                                                 wxSscanf(readlinesubtext.AfterFirst(wxT('[')).BeforeFirst(wxT(']')),wxT("%d"),&line->nameid);
00133                                                 
00134                                                 line->parents = false;
00135                                                 line->pline = true;
00136                                                 line->child = false;
00137                                                 line->cycle = true;
00138                                                 line->recursive = false;
00139                                         }
00140                                         else if(isplus) //[4]      3.7    0.00    0.01       1+6       quicksort(int*, int, int) [4]
00141                                         {
00142                                                 sscanf((const char*)readlinetext.mb_str(conv),"[%d] %f %f %f %d %d %[^\n]s",&line->index,&line->time,&line->self,&line->childern,&line->called0,&line->called1,nameandid);
00143                                                 //
00144                                                 wxString readlinesubtext(nameandid, conv);
00145                                                 //
00146                                                 line->name = readlinesubtext.BeforeFirst(wxT('['));
00147                                                 //
00148                                                 wxSscanf(readlinesubtext.AfterFirst(wxT('[')).BeforeFirst(wxT(']')),wxT("%d"),&line->nameid);
00149                                                 line->parents = false;
00150                                                 line->pline = true;
00151                                                 line->child = false;
00152                                                 line->cycle = false;
00153                                                 line->recursive = true; 
00154                                         }
00155                                         else if (!readlinetext.Contains(wxT('('))) // [3]    100.0    0.00    0.03       %d - neni        main [3]
00156                                         {       
00157                                                 //specialni pripad - problem jiny zapis na webu a v gmon.out.txt
00158                                                 sscanf((const char*)readlinetext.mb_str(conv),"[%d] %f %f %f %[^\n]s",&line->index,&line->time,&line->self,&line->childern,nameandid);
00159                                                 //
00160                                                 wxString readlinesubtext(nameandid, conv); // musi byt kodovani ?
00161                                                 line->name = readlinesubtext.BeforeFirst(wxT('['));
00162                                                 //
00163                                                 wxSscanf(readlinesubtext.AfterFirst(wxT('[')).BeforeFirst(wxT(']')),wxT("%d"),&line->nameid);
00164                                                 line->parents = false;
00165                                                 line->pline = true;
00166                                                 line->child = false;
00167                                                 line->cycle = false;
00168                                                 line->recursive = false;
00169                                         }
00170                                         else //[2]    100.00    0.16     1.77    1      main [2]
00171                                         {                                       
00172                                                 sscanf((const char*)readlinetext.mb_str(conv),"[%d] %f %f %f %d %[^\n]s",&line->index,&line->time,&line->self,&line->childern,&line->called0,nameandid);
00173                                                 //
00174                                                 wxString readlinesubtext(nameandid, conv); // musi byt kodovani ?
00175                                                 line->name = readlinesubtext.BeforeFirst(wxT('['));
00176                                                 //
00177                                                 wxSscanf(readlinesubtext.AfterFirst(wxT('[')).BeforeFirst(wxT(']')),wxT("%d"),&line->nameid);
00178                                                 line->parents = false;
00179                                                 line->pline = true;
00180                                                 line->child = false;
00181                                                 line->cycle = false;
00182                                                 line->recursive = false;
00183                                         
00184                                         }
00185                                 }
00186                                 else  //parents and childern
00187                                 {
00188                                         if(iscycle && !islom) //3          a <cycle 1> [5] 
00189                                         {                                                                                                                                                               // warning                                      
00190                                                 sscanf((const char*)readlinetext.mb_str(conv),"%d %[^\n]s",&line->called0,nameandid);
00191                                                 wxString readlinesubtext(nameandid, conv);
00192                                                 line->name = readlinesubtext.BeforeFirst(wxT('<'));
00193                                                 wxSscanf(readlinesubtext.AfterFirst(wxT('<')).BeforeFirst(wxT('>')),wxT("cycle %d"), &line->cycleid);
00194                                                  //line->cycleid = readlinesubtext.AfterFirst('<').BeforeFirst('>');
00195                                                 wxSscanf(readlinesubtext.AfterFirst(wxT('[')).BeforeFirst(wxT(']')),wxT("%d"),&line->nameid);
00196                                                 
00197                                                 line->cycle = true;
00198                                                 line->recursive = false;
00199                                                 
00200                                         }
00201                                         else if(!iscycle && islom) // 0        0    6/6        c [6]
00202                                         {
00203                                                 sscanf((const char*)readlinetext.mb_str(conv),"%f %f %d/%d %[^\n]s",&line->self,&line->childern,&line->called0,&line->called1,nameandid);
00204                                                 wxString readlinesubtext(nameandid, conv);
00205                                                 line->name = (wxString)readlinesubtext.BeforeFirst(wxT('['));
00206                                                 wxSscanf(readlinesubtext.AfterFirst(wxT('[')).BeforeFirst(wxT(']')),wxT("%d"),&line->nameid);
00207                                         
00208                                                 line->cycle = false;
00209                                                 line->recursive = false;
00210                                                 //
00211                                         }
00212                                         else if(iscycle && islom) //1.77        0    1/1        a <cycle 1> [5]
00213                                         {
00214                                                 sscanf((const char*)readlinetext.mb_str(conv),"%f %f %d/%d %[^\n]s",&line->self,&line->childern,&line->called0,&line->called1,nameandid);
00215                                                 wxString readlinesubtext(nameandid, conv); // musi byt kodovani ?
00216                                                 line->name = readlinesubtext.BeforeFirst(wxT('<'));
00217                                                 wxSscanf(readlinesubtext.AfterFirst(wxT('<')).BeforeFirst(wxT('>')),wxT("cycle %d"), &line->cycleid);
00218                                                  //line->cycleid = readlinesubtext.AfterFirst('<').BeforeFirst('>');
00219                                                 wxSscanf(readlinesubtext.AfterFirst(wxT('[')).BeforeFirst(wxT(']')),wxT("%d"),&line->nameid);
00220                                                 
00221                                                 line->cycle = true;
00222                                                 line->recursive = false;
00223                                                 
00224                                         }
00225                                         else if(!iscycle && !islom && !isdot) //15             faktorial(int) [8]
00226                                         {
00227                                                 sscanf((const char*)readlinetext.mb_str(conv),"%d %[^\n]s",&line->called0,nameandid);
00228                                                 wxString readlinesubtext(nameandid, conv); // musi byt kodovani ?
00229                                                 line->name = readlinesubtext.BeforeFirst(wxT('['));
00230                                                 wxSscanf(readlinesubtext.AfterFirst(wxT('[')).BeforeFirst(wxT(']')),wxT("%d"),&line->nameid);
00231                                                 
00232                                                 line->cycle = false;
00233                                                 line->recursive = true;
00234                                                 
00235                                         }
00236                                         /*else if(!iscycle && !islom)
00237                                         {
00238                                                 sscanf((const char*)readlinetext.mb_str(conv),"%f %f %d %[^\n]s",&line->self,&line->childern,&line->called0,nameandid);
00239                                                 //
00240                                                 wxString readlinesubtext(nameandid, conv); // musi byt kodovani ?
00241                                                 line->name = readlinesubtext.BeforeFirst('[');
00242                                                 //
00243                                                 wxSscanf(readlinesubtext.AfterFirst('[').BeforeFirst(']'),"%d",&line->nameid);
00244                                                 
00245                                                 line->cycle = false;
00246                                                 line->recursive = false;
00247                                                 //
00248                                         }*/
00249                                         
00250                                         if (primaryline)
00251                                         
00252                                         {
00253                                                 line->parents = false;
00254                                                 line->pline = false;
00255                                                 line->child = true;
00256                                         }
00257                                         else
00258                                         {
00259                                                 line->parents = true;
00260                                                 line->pline = false;
00261                                                 line->child = false;
00262                                         }
00263                                 }
00264                                 lines.Append( line );
00265                         }
00266                 }
00267                 else if (lineheader) 
00268                 {
00269                         break;
00270                 }
00271         }
00272 }
 All Classes Files Functions Variables